<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>放大缩小scale</title>
</head>

<body>


  <script src="../node_modules/d3/build/d3.min.js"></script>
  <script>
    const width = 500,
      height = 500,
      radius = 150,
      data = [22, 33, 17, 9, 26],
      colors = d3.schemeCategory10;


    // 放大缩小
    let zoom = d3.zoom().scaleExtent([0.3, 5])
      .on('zoom', function () {
        d3.select(this).attr('transform', d3.event.transform);
      });
    let pie = d3.pie(),
      pieData = pie(data);
    let svg = d3.select('body').append('svg').attr('width', width).attr('height', height).call(zoom);
    let arc = d3.arc().innerRadius(0).outerRadius(radius);

    let arcs = svg.selectAll('g').data(pieData).enter().append('g')
      .attr('transform', `translate(250,200)`);

    arcs.append('path').attr('fill', function (d, i) {
      // console.log(d);
      return colors[i];
    }).attr('d', function (d) {
      return arc(d);
    });
  </script>

</body>

</html>